<template>
  <div class="landAreaStatistics">
      <div class="tabs">
          <zlc-tabs :datas="tabs" @select="changeTab"></zlc-tabs>
      </div>
      <div class="data">
        <div class="item" v-for="(item, index) in list" :key="index">
            <zlc-progress :name="item.name" :value="item.areaCount" :sort="index" :count="count">

            </zlc-progress>
        </div>
          <zlc-nodata v-if="!list || !list.length"></zlc-nodata>
      </div>
  </div>
</template>

<script>
import zlcTabs from "/src/components/zlcTabs/zlcTabs.vue";
import zlcProgress from "/src/components/zlcProgress/zlcProgress.vue";
import zlcNodata from "../../../components/zlcNodata/zlcNodata.vue";
import {watch, ref, toRefs} from "vue";
export default {
    name: "landAreaStatistics",
    components:{
        zlcTabs,
        zlcProgress,
        zlcNodata
    },
    props:{
      data:{
          type: Object,
          default(){
              return {}
          }
      }
    },
    setup(props, ctx){
        let tabs = ref([
            {
                name: '基地',
                field: 'dbBaseAreaList'
            },
            {
                name: '楼栋',
                field: 'dbBaseBuildingAreaList'
            },
            {
                name: '房号',
                field: 'dbOtherIndependentHouseAreaList'
            },
            {
                name: '独立房产',
                field: 'dbUnitHouseAreaList'
            }
        ])
        let datasCopy = ref({})
        let list = ref([])
        let count = ref(0)
        watch(() => props.data, newVal => {
            datasCopy.value = newVal
            changeTab({ field: 'dbBaseAreaList' })

        }, { deep: true })

        let changeTab = val => {
            list.value = datasCopy.value[val.field]
            if(!list.value) return
            count.value = list.value.map(item => item.areaCount).reduce((pre, next) => pre + next, 0)
        }



        return {
            tabs,
            list,
            count,
            changeTab
        }
    }
}
</script>

<style scoped lang="less">
.landAreaStatistics{
  width: 100%;
  height: 100%;
  padding-top: 10px;
  box-sizing: border-box;
  .tabs{
    width: 100%;
    height: 30px;
    line-height: 30px;
    margin-bottom: 10px;
  }
  .data{
    width: 100%;
    height: calc(100% - 50px);
    overflow-y: auto;
    /* 滚动条优化 start */
    &::-webkit-scrollbar {
      width: 6px;
      height: 6px;
    }

    /* 无内容时的滚动条样式 */
    &::-webkit-scrollbar-track {
      -webkit-box-shadow: inset 0 0 5px rgba(0, 0, 0, 0.2);
      border-radius: 4px;
      background: rgba(9, 108, 222, .4);
    }

    /* 有内容时的滚动条样式 */
    &::-webkit-scrollbar-thumb {
      background: rgb(9, 108, 222);
      border-radius: 4px;
    }

    &::-webkit-scrollbar-thumb:hover {
      background: rgb(94, 164, 245);
    }

    &::-webkit-scrollbar-corner {
      background: rgba(9, 108, 222, .4);
    }

    /* 滚动条优化 end */
  }
}
</style>
